﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using childApp.common;

namespace childApp.member
{
    public partial class MemModifyForm : Form
    {
        public MemModifyForm()
        {
            InitializeComponent();
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            if (modifyMem())
            {
                MessageBox.Show("数据更新成功！");
            }
            else
            {
                MessageBox.Show("数据更新失败！");
            }

            this.Close();
            this.Dispose();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (delMem())
            {
                MessageBox.Show("数据删除成功！");
            }
            else
            {
                MessageBox.Show("数据删除失败！");
            }

            this.Close();
            this.Dispose();
        }

        private Boolean delMem()
        {
            string id = this.lbNo.Text;
            StringBuilder sb = new StringBuilder("delete from member where id = " + id);
            return DbCommon.Getsqlcom(sb.ToString());
        }

        private Boolean modifyMem()
        {

            string sex = this.cmbSex.Text;
            string id = this.lbNo.Text;
            string name = this.txtName.Text;
            string addr = this.txtAddr.Text;
            string score = this.txtScore.Text;
            string birth = this.dtpBirth.Text;

            StringBuilder sb = new StringBuilder("update member set [sex]='" + sex + "',[name]='" + name + "',[addr]='" + addr + "' , [score] = '" + score + "',[birth] = '" + birth + "' where [id] = " + id);
            //         StringBuilder sb = new StringBuilder("update member set [name]='" + name + "', [addr]='" + addr + "',[score] = '" + score + "',[birth] = '" + birth + "' where [id] = " + id);

            return DbCommon.Getsqlcom(sb.ToString());

        }
    }
}
